(function(){
    if (!checkConnect()) return;
    //设定翻页模块的参数
    publicParam.memberSize = 9;
    getNode("refresh").onclick = ()=>{
        //强制刷新
        publicParam.members = null;
        publicParam.memberPage = 0;
        init();
    }
    init();
    /**
    * 初始化
    */
    async function init(){
        var rtn = await loadManbers();
        if (rtn){
            if(!publicParam.memberPage) publicParam.memberPage = 0;
            if(publicParam.memberCount>publicParam.memberSize){
                //因为翻页模块可以在多个页面中使用，因此不直接使用全局变量，而是传一组局域变量给它
                var param = {
                    total:publicParam.memberCount,
                    size:publicParam.memberSize,
                    current:publicParam.memberPage,
                    fn:showMember,
                };
                loadPage("/common/paging","paging",param);
            }
            showMember(publicParam.memberPage);
        }
    }
    /**
    * 显示会员列表
    */
    function showMember(paging){
        publicParam.memberPage = paging;
        var memberList = getNode("memberList");
        var row = memberList.children[0];
        clearAll(memberList);
        //计算翻页的起止位置
        var from = publicParam.memberPage*publicParam.memberSize;
        var to = (publicParam.memberPage+1)*publicParam.memberSize;
        to = Math.min(publicParam.members.length,to);
        for(var i=from;i<to;i++){
            var m = publicParam.members[i];
            var newRow = row.cloneNode(true);
            newRow.style.display="";
            var name = getSubNode(newRow,"name");
            name.innerText = m.name;
            //非正式会员的名字用红色显示
            if (!m.isReal) name.style.color="#FD4766";
            else name.style.color="";
            var joinTime = getSubNode(newRow,"joinTime");
            joinTime.innerText = m.joinTime;
            var about = getSubNode(newRow,"about");
            about.innerText = m.about;
            var photo = getSubNode(newRow,"photo");
            if (m.photo) photo.src=m.photo;
            else photo.src="/images/my.png";
            //为了让每个会员都可以点击查看，设置传递的参数
            newRow.tag = m.address;
            newRow.onclick=function(){
                goto("member/info",this.tag);
            };
            memberList.appendChild(newRow);
        }
    }
})();